const http=require('http')
const os=require("os")
const {time}=require('./utils')

//创建web服务器
const server=http.createServer()

server.on('request',(request,response)=>{
  const ip=request.socket.remoteAddress
    if(request.url!=='/favicon.ico'){
        console.log(time());
        // console.log(request.headers['user-agent']);
        console.log(request.url);
    
        console.log(ip)
        console.log(request.headers);
        console.log(request.method)
    }
    // response.setHeader('Content-Type','text/plain;charset=utf-8')
    // response.setHeader('Content-Type','text/html;charset=utf-8')
    response.setHeader('Content-Type','application/json;charset=utf-8')

  
    // response.end('你好啊')
    // response.end('<h3>你好啊</h3>')
    response.end(JSON.stringify({id:1,name:'张三'}))
})
server.listen(3000,'0.0.0.0',()=>{
    console.log('服务器启动 http://127.0.0.1:3000');
})